﻿using System;
using Foothill.Common.Logging;
using Foothill.IoC;
using Foothill.Service.Caching;
using StructureMap;

namespace Foothill.Web
{
    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            IocContainer.RegisterAllTypes(Server.MapPath("~\\Bin"), AssemblyList.FoothillAssemblies);

            ILocalCache localCache = IocContainer.GetInstance<ILocalCache>();
            localCache.Refresh();
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            System.Security.Cryptography.RSACryptoServiceProvider.UseMachineKeyStore = true;
            System.Security.Cryptography.DSACryptoServiceProvider.UseMachineKeyStore = true;
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
        }

        protected void Application_Error(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError();
            Log.Error(FoothillModule.Unknown, "Unhandled General Exception!", ex);

            Server.Transfer("~/Error/ErrorOccurred.aspx");
        }

        protected void Session_End(object sender, EventArgs e)
        {
        }

        protected void Application_End(object sender, EventArgs e)
        {
        }
    }
}